package com.hamster.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hamster.crm.pojo.Permission;
import com.hamster.crm.pojo.dto.PermissionGroupDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Tarry
 * @create 2019/12/28 8:31
 */
@Repository
@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {

    //分组查询权限
    @Select("select group_name from tb_permission group by group_name")
    @Results({
      @Result(property = "groupName",column = "group_name"),
      @Result(property = "permissionList",column = "group_name",many = @Many(select = "com.hamster.crm.mapper.PermissionMapper.queryPermissionByGroupName")),
    })
    List<PermissionGroupDTO> listPermissions();

    @Select("select * from tb_permission where group_name = #{groupName}")
    List<Permission> queryPermissionByGroupName(@Param("groupName") String groupName);


}
